package com.jishuo.nontax.web.bill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.BackpaybillVO;
import com.jishuo.nontax.bfc.service.BackBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 退付书
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/backpaybill", name = "退付书")
@UserAuthority(menu = {"bill/backpaybill/backpaybill"})
public class BackPayBillController {

    @Resource
    private BackBillService backBillService;
    @Resource
    private UserService userService;

    // 页面文件位置
    private String prefix = "bill/";

    @RequestMapping(value = {"backpaybill"}, name = "退付书首页")
    public String index() {
        return prefix + "backpaybill";
    }

    /**
     * @author hlp
     * @date 2023/3/7 17:42
     * @Description: 退付书列表
     */
    @ResponseBody
    @RequestMapping(value = "findBackPayBillPage", name = "退付书列表")
    public GridResult<BackpaybillVO> findBackPayBillPage(BackpaybillVO backpaybillVO , Pagination pagination) {
        return new GridResult<>(backBillService.findBackPayBillPage(backpaybillVO,pagination));
    }

    @ResponseBody
    @RequestMapping(value = "/sendBackpaybill",name="向财政发送退付书")
    public BaseResult sendBackpaybill(String billids, String usercode, String userpwd, HttpSession session) {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return backBillService.sendBackpaybill(billids);
    }


    @ResponseBody
    @RequestMapping(value = "/cleanBackpaybill",name="冲销退付书")
    public BaseResult cleanBackpaybill(String billids,String usercode,String userpwd, HttpSession session) {
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return backBillService.cleanBackpaybill(billids,usercode);
    }

    @ResponseBody
    @RequestMapping(value = "backPayBillExport", name = "退付书导出")
    public void backPayBillExport(long bankid, String paybankdt, HttpServletResponse response) throws IOException {
        backBillService.backPayBillExport(bankid, paybankdt, response);
    }
}
